import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  //登陆
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //404
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  //工作台
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'el-icon-menu' }
    }]
  },
  //订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/order/list'),
        meta: { title: '订单列表', icon: '' },
      },
      {
        path: 'detail',
        name: 'Detail',
        component: () => import('@/views/order/detail'),
        hidden: true,
        meta: { title: '订单详情', icon: '' }
      }
    ]
  },
  //系统管理
  {
    path: '/setting',
    component: Layout,
    meta: { title: '系统设置', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'truck',
        name: 'Truck',
        component: () => import('@/views/setting/truck'),
        meta: { title: '车辆管理', icon: '' }
      },
      {
        path: 'driver',
        name: 'Driver',
        component: () => import('@/views/setting/driver'),
        meta: { title: '司机管理', icon: '' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  //mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
